<?php

use yii\helpers\Url;
use yii\helpers\Html;
use website\helpers\Render;
use common\models\Design;
use common\models\Recruit;
use common\models\RecruitApplicant;

$this->title = '投递管理';
?>
<style>
    #info-table td {padding:10px;}
    #info-table td .flyer-status {margin-right:0 !important;}
</style>

<div class="contenter">
    <?= $this->render('/user/navigator', ['active' => 'recruit-applicant-list']) ?>

    <div id="user-contenter">
        <div class="box-shadow pb-20px" id="sub-contenter">
            <div class="data-title"><span class="h3"><?= $this->title ?></span></div>
            <div class="flyer-table simple">
                <table id="info-table" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr><td colspan="2"><i class="icon-search"></i> 数据加载中，请稍后.</td></tr>
                    </tbody>
                </table>
            </div>
            <div class="flyer-page mt right" id="info-page">
                <div class="html mr-10px"></div>
            </div>
        </div>
    </div>
</div>
<div style="display:none;">
    <?= Render::select('', Recruit::$typeSelector, null, ['id' => 'recruit-type']) ?>
    <?= Render::select('', RecruitApplicant::$statusSelector, null, ['id' => 'recruit-status']) ?>
    <?= Render::select('', $categories, null, ['id' => 'categories']) ?>
    <?= Render::select('', Design::$styleSelector, null, ['id' => 'styles']) ?>
</div>

<script src="<?= Render::static('art-template/template.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tabler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // 初始化表格异步加载事件
        (new tabler).init({
            // 请求地址
            url: '<?= Url::to('@web/designer/recruit-applicant-list') ?>',
            // 数据渲染配置
            table: '#info-table', page: '#info-page', template: 'info-template', search: '#info-search', readyCall: true,
            // param => tabler
            afterPost: function(param) {
                // 名称显示
                var lists = [['.type', '#recruit-type'], ['.status', '#recruit-status'], ['.categories', '#categories'], ['.styles', '#styles']];
                for(var i = 0; i < lists.length; ++i) {
//                    tableHandler.renderCategory({ category: $(param.tabler).find(lists[i][0]), select: lists[i][1], color: false });
                    tableHandler.renderCategory({ category: $(param.tabler).find(lists[i][0]), select: lists[i][1], color: false, splite: '，' });
                }
                // 撤销投递申请
                tableHandler.requestSingle({
                    button: '.revoke-data', isConfirm: true, isShadow: false,
                    url: "<?= Url::to('@web/designer/recruit-applicant-revoke') ?>",
                    beforeRequest: function(param) {
                        $(param.mthis).attr('disabled', true);
                    },
                    requestFail: function(param) {
                        $(param.mthis).removeAttr('disabled');
                    },
                    requestSuccess: function (param) {
                        layer.alert(param.response.message, { icon: 6 }, function() {
                            $(param.mthis).after('<span class="flyer-status red">已撤销</span>');
                            $(param.mthis).remove();
                            layer.closeAll();
                        });
                    }
                });
            }
        });
    });
</script>
<script id="info-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <tr id="tr-{{info.id}}" data-id="{{info.id}}">
        <td class="first">
            <p><a href="<?= Url::to('@web/seer/recruit?id=') ?>{{info.id}}">{{info.recruit.title}}</a></p>
            <p>
                <span class="w-180px inline-block">投递日期：{{info.created_at | dateShow: format = 'day'}}</span>
                <span class="w-180px inline-block">行业类型：<span class="categories">{{info.recruit.categories}}</span></span>
                <span class="w-300px inline-block">设计风格：<span class="styles">{{info.recruit.styles}}</span></span>
                <span class="w-180px inline-block">投递状态：<span class="status">{{info.status}}</span></span>
            </p>
        </td>
        <td class="tar">
            <p><i class="icon-double-angle-right"></i> <span class="type">{{info.recruit.type}}</span></p>
            <p>
                {{if info.status == '<?= RecruitApplicant::StatusExamine ?>'}}
                <a class="flyer-button normal border-round narrow thin revoke-data"><i class="icon-reply"></i> 撤销投递</a>
                {{/if}}
            </p>
        </td>
    </tr>
    {{/each}}
    {{else}}
    <tr>
        <td class="first" colspan="2"><i class="icon-ban-circle"></i> 搜索程序未为您搜索到任何信息！</td>
    </tr>
    {{/if}}
</script>
</script>